package com.yztc.love_travel.ui.mainservice.scenerystrategy.presenter;

import com.yztc.love_travel.bean.SceneryStrategyBean;
import com.yztc.love_travel.ui.mainservice.scenerystrategy.model.ISceneryStrategyModel;
import com.yztc.love_travel.ui.mainservice.scenerystrategy.model.SceneryStrategyModelImpl;
import com.yztc.love_travel.ui.mainservice.scenerystrategy.view.ISceneryStrategyView;

import java.util.Map;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by My on 2016/11/29.
 */

public class SceneryStrategyPresenterImpl implements ISceneryStrategyPresenter{
    private ISceneryStrategyModel mISceneryStrategyModel;
    private ISceneryStrategyView mISceneryStrategyView;

    public SceneryStrategyPresenterImpl(ISceneryStrategyView mISceneryStrategyView) {
        mISceneryStrategyModel=new SceneryStrategyModelImpl();
        this.mISceneryStrategyView = mISceneryStrategyView;
    }

    @Override
    public void getSceneryStrategyBean(String baseUrl, Map<String, Object> params) {
        mISceneryStrategyModel.getSceneryStrategyBean(baseUrl,params)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<SceneryStrategyBean>() {
                    @Override
                    public void onCompleted() {
                        mISceneryStrategyView.loadFinish();
                    }

                    @Override
                    public void onError(Throwable e) {
                        mISceneryStrategyView.loadError();

                    }

                    @Override
                    public void onNext(SceneryStrategyBean sceneryStrategyBean) {
                        mISceneryStrategyView.showSceneryStrategyData(sceneryStrategyBean);
                    }

                    @Override
                    public void onStart() {
                        super.onStart();
                        mISceneryStrategyView.loadStart();
                    }
                });

    }
}
